package tmpl

const WebTmpl = `
package web

import (
{{if .IsService}}
    "gitee.com/xiao_hange/go-admin-pkg/internal/service"
{{end}}
    "github.com/gin-gonic/gin"
)

var _ handler = &{{.TypeName}}Handler{}

type {{.TypeName}}Handler struct {
{{if .IsService}}svc service.{{.TypeName}}Server{{end}}
}

func New{{.TypeName}}Handler({{if .IsService}}svc service.{{.TypeName}}Server{{end}}) *{{.TypeName}}Handler {
    return &{{.TypeName}}Handler{
{{if .IsService}}svc: svc,{{end}}
    }
}

func ({{.ReceiverName}}) RegisterRoutes(server *gin.Engine) {
    _ = server.Group("/{{.GroupName}}")
}
`
const ServerTmpl = `
package service
{{if .IsRepo}}
import "gitee.com/xiao_hange/go-admin-pkg/internal/repository"
{{end}}
type {{.TypeName}}Server interface {
}

type {{.ReceiverName}}Server struct {
{{if .IsRepo}}repo repository.{{.TypeName}}Repository{{end}}
}

func New{{.TypeName}}Server({{if .IsRepo}}repo repository.{{.TypeName}}Repository{{end}}) {{.TypeName}}Server {
	return &{{.ReceiverName}}Server{
{{if .IsRepo}}repo:repo,{{end}}
    }
}
`

const RepositoryTmpl = `
package repository
{{if .IsDao}}
import "gitee.com/xiao_hange/go-admin-pkg/internal/repository/dao"
{{end}}
type {{.TypeName}}Repository interface {
}

type {{.ReceiverName}}Repository struct {
{{if .IsDao}}dao dao.{{.TypeName}}Dao{{end}}
}

func New{{.TypeName}}Repository({{if .IsDao}}dao *dao.{{.TypeName}}Dao{{end}}) {{.TypeName}}Repository {
	return &{{.ReceiverName}}Repository{
{{if .IsDao}}dao:dao,{{end}}
    }
}
`
const DaoTmpl = `
package dao

import "gorm.io/gorm"

type {{.TypeName}}Dao interface {
}

type {{.ReceiverName}}Dao struct {
	db *gorm.DB
}

func New{{.TypeName}}Dao(db *gorm.DB) {{.TypeName}}Dao {
	return &{{.ReceiverName}}Dao{
		db: db,
	}
}

type {{.TypeName}} struct{
    ID            int64 ` + "`gorm:\"primaryKey;autoIncrement\"`" + `
	Status        int32 ` + "`gorm:\"default:1;comment:'状态 1:正常，2：禁用，-1：删除'\"`" + `
    CreateTime    int64
	UpdateTime    int64
}
`
